package cc.wanforme.fsync.entity.device;

import java.io.IOException;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.List;

/** 盘信息 */
public class DeviceInfo {

    private String name; // 盘名称
    private String type; // 文件系统类型
    private long totalSpace; // 总空间
    private long usableSpace; // 剩余空间

    /** 当前操作系统的所有逻辑磁盘信息 */
    public static List<DeviceInfo> systemInfo() throws IOException {
        List<DeviceInfo> list = new ArrayList<>();
        FileSystem fs = FileSystems.getDefault();
        Iterable<FileStore> fileStores = fs.getFileStores();
        for (FileStore store : fileStores) {
            DeviceInfo info = new DeviceInfo();
            info.setName(store.toString());
            info.setType(store.type());
            info.setTotalSpace(store.getTotalSpace());
            info.setUsableSpace(store.getUsableSpace());
            list.add(info);
        }
        return list;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public long getTotalSpace() {
        return totalSpace;
    }

    public void setTotalSpace(long totalSpace) {
        this.totalSpace = totalSpace;
    }

    public void setUsableSpace(long usableSpace) {
        this.usableSpace = usableSpace;
    }

    public long getUsableSpace() {
        return usableSpace;
    }
}
